Credentials Transfer

工作流概述

这是一个包含22个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "tlnJNm9t5H3VLU5K",
  "meta": {
    "instanceId": "505c2bdb4483cbbca32871c0acd4b60c83809f177e47e2864f71c1c1760a9b2a",
    "templateCredsSetupCompleted": true
  },
  "name": "Credentials Transfer",
  "tags": [],
  "nodes": [
    {
      "id": "9bb3fd8d-cead-4325-9c77-2c1d203ac805",
      "name": "Success",
      "type": "n8n-nodes-base.form",
      "position": [
        680,
        300
      ],
      "webhookId": "6a630d50-a4b6-4fd7-a7a7-fa0283996903",
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "✅ Transfer completed",
        "completionMessage": "=The credential has been transfered."
      },
      "typeVersion": 1
    },
    {
      "id": "0c90e8d6-3230-4139-a625-e8656fe1c4d9",
      "name": "Error",
      "type": "n8n-nodes-base.form",
      "position": [
        680,
        460
      ],
      "webhookId": "bfaa86b9-fddf-47b3-9456-caba547a1f5e",
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "⚠️ Transfer failed",
        "completionMessage": "=Please check the workflow settings"
      },
      "typeVersion": 1
    },
    {
      "id": "050bb8b6-faf5-4190-a727-986d7fe6b28a",
      "name": "Create Credential",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        460,
        340
      ],
      "parameters": {
        "url": "={{ $json.instance.baseUrl }}/credentials",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.credential.name }}"
            },
            {
              "name": "type",
              "value": "={{ $json.credential.type }}"
            },
            {
              "name": "data",
              "value": "={{ $json.credential.data }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "X-N8N-API-KEY",
              "value": "={{ $json.instance.apiKey }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "17072ec2-526c-49b4-8384-e9ca347b8748",
      "name": "Get Instance Names",
      "type": "n8n-nodes-base.code",
      "position": [
        680,
        -240
      ],
      "parameters": {
        "jsCode": "dropDownValues = [];

for (const instance of $input.first().json.remoteInstances) {
  dropDownValues.push({\"option\": instance.name});
}

return { \"options\": JSON.stringify(dropDownValues) };"
      },
      "typeVersion": 2
    },
    {
      "id": "27fdd4c4-5c39-497b-91b3-e468b20e8f8c",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "position": [
        460,
        -240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8a5d50fc-95dc-40b3-a3f2-293521bab29a",
              "name": "remoteInstances",
              "type": "array",
              "value": "=[
  {
    \"name\": \"n8n-test-01\",
    \"apiKey\": \"n8n_api_26b5bb6d39d337bd904f3d89fe88562d456c1cd13af401f490145206f2dc516ffa1fed04a26ae689\",
    \"baseUrl\": \"https://n8n-test-01.services.octionic.com/api/v1\"
  }
]"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "76b7d9d2-c919-42a6-8724-8771d9415e3e",
      "name": "Export Credentials",
      "type": "n8n-nodes-base.executeCommand",
      "position": [
        240,
        40
      ],
      "parameters": {
        "command": "n8n export:credentials --all --pretty --decrypted --output=/tmp/cred"
      },
      "typeVersion": 1
    },
    {
      "id": "b5f53aa1-ccf6-43b0-9f4c-cfc52f99aabf",
      "name": "Get Credentials Data",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        460,
        40
      ],
      "parameters": {
        "options": {},
        "fileSelector": "/tmp/cred"
      },
      "typeVersion": 1
    },
    {
      "id": "16fdae2d-f3e6-4030-859a-ecba74dfe4c2",
      "name": "Binary to JSON",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        680,
        40
      ],
      "parameters": {
        "options": {},
        "operation": "fromJson"
      },
      "typeVersion": 1
    },
    {
      "id": "3d590285-e82c-4754-8618-2a52fcda6253",
      "name": "Get Credential Names",
      "type": "n8n-nodes-base.code",
      "position": [
        900,
        40
      ],
      "parameters": {
        "jsCode": "dropDownValues = [];

for (const credential of $input.first().json.data) {
  dropDownValues.push({\"option\": credential.name});
}

return { \"options\": JSON.stringify(dropDownValues) };"
      },
      "typeVersion": 2
    },
    {
      "id": "21615934-6834-4b4e-b521-942a24f64388",
      "name": "Choose Instance",
      "type": "n8n-nodes-base.form",
      "position": [
        900,
        -240
      ],
      "webhookId": "b1fc6927-ebe8-4a02-9d64-24bf6f6d0db6",
      "parameters": {
        "options": {
          "formTitle": "Select Destination",
          "buttonLabel": "Continue",
          "formDescription": "Choose the n8n instance where the credential should be copied to"
        },
        "defineForm": "json",
        "jsonOutput": "=[
   {
      \"fieldLabel\": \"Destination\",
      \"fieldType\": \"dropdown\",
      \"requiredField\": true,
      \"fieldOptions\": {
        \"values\": {{ $json.options }}
      }
   }
]"
      },
      "typeVersion": 1
    },
    {
      "id": "d36a41c4-6ed3-4939-8562-e3f50ffcd72b",
      "name": "Choose Credential",
      "type": "n8n-nodes-base.form",
      "position": [
        1120,
        40
      ],
      "webhookId": "f732b37b-6623-4629-bc7d-99ebb56a9809",
      "parameters": {
        "options": {
          "formTitle": "Select Credential",
          "buttonLabel": "Copy now",
          "formDescription": "Choose the credential which should be copied"
        },
        "defineForm": "json",
        "jsonOutput": "=[
   {
      \"fieldLabel\": \"Credential\",
      \"fieldType\": \"dropdown\",
      \"requiredField\": true,
      \"fieldOptions\": {
        \"values\": {{ $json.options }}
      }
   }
]"
      },
      "typeVersion": 1
    },
    {
      "id": "4391f0d9-3ed5-4e2b-a761-ab7bf41959f1",
      "name": "Prepare Request Data",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        340
      ],
      "parameters": {
        "jsCode": "output = {};

for (const credential of $('Binary to JSON').first().json.data) {
  if (credential.name == $input.first().json.Credential) {
    output.credential = credential;
  }
}

for (const instance of $('Settings').first().json.remoteInstances) {
  if (instance.name == $('Choose Instance').first().json.Destination) {
    output.instance = instance;
  }
}

return output;"
      },
      "typeVersion": 2
    },
    {
      "id": "571cd727-218b-4a5d-97fe-a8dcbcf15cce",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -340
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "## Setup instances
Each instnce requires a name, apiKey and baseURL"
      },
      "typeVersion": 1
    },
    {
      "id": "7f717bed-fac5-4b1e-acc7-a6ad9d1c4be4",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -340
      ],
      "parameters": {
        "color": 5,
        "width": 527.8711162255479,
        "height": 223.19907940161124,
        "content": "## Instances config example
```
[
  {
    \"name\": \"n8n-test\",
    \"apiKey\": \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",
    \"baseUrl\": \"https://n8n-test.example.com/api/v1\"
  },
  {
    ...
  }
]
```"
      },
      "typeVersion": 1
    },
    {
      "id": "5e27ad60-7e65-452d-8c33-56c6c85911d3",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        180,
        -340
      ],
      "parameters": {
        "color": 7,
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "A form with no input fields initiates the process.
*Consider securing the form using Basic Auth.*"
      },
      "typeVersion": 1
    },
    {
      "id": "0b69effa-44e4-41e1-bb5d-934ed19b8488",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        180,
        -60
      ],
      "parameters": {
        "color": 7,
        "width": 655.5152156976209,
        "height": 255.86856541619233,
        "content": "Credentials are being fetched using the cmd tools, since there is no API endpoint available for this. The data is then converted into a JSON object."
      },
      "typeVersion": 1
    },
    {
      "id": "a0f83646-dcf3-4893-bca0-a2b0ec4942b6",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        620,
        -340
      ],
      "parameters": {
        "color": 7,
        "width": 435.9715408127852,
        "height": 255.86856541619233,
        "content": "A list of the instance names is being extracted from the settings and used as dynamic options for the dropdown in a new form page."
      },
      "typeVersion": 1
    },
    {
      "id": "78611a9e-5949-44c4-af23-78e8f689de2b",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        840,
        -60
      ],
      "parameters": {
        "color": 7,
        "width": 435.9715408127852,
        "height": 255.86856541619233,
        "content": "A list of the credential names is being extracted from the settings and used as dynamic options for the dropdown in a new form page."
      },
      "typeVersion": 1
    },
    {
      "id": "23e9b0ea-f6a7-4072-8e87-292ba432a24d",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        180,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "Based on the selections made by the user, the necessary data is being provided."
      },
      "typeVersion": 1
    },
    {
      "id": "f13a3bce-d92d-4e2c-bb63-b37c4aa89b9b",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "The credential data is being transferred to the selected instance based using dynamic authentication"
      },
      "typeVersion": 1
    },
    {
      "id": "1788ed42-44be-41c3-8a45-3d8c74925ded",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        620,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 216.47293010628914,
        "height": 376.16893354714523,
        "content": "Display a confirmation/error message to the user"
      },
      "typeVersion": 1
    },
    {
      "id": "58cbb873-906e-4215-b501-4a1b31fdcbd9",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        240,
        -240
      ],
      "webhookId": "f6c627e5-e93c-4ee1-9605-ebdfa5fff286",
      "parameters": {
        "options": {
          "buttonLabel": "Begin",
          "appendAttribution": false
        },
        "formTitle": "Credential Transfer",
        "formFields": {
          "values": [
            {
              "fieldLabel": " ",
              "placeholder": "Click \"Begin\" to continue"
            }
          ]
        },
        "formDescription": "This tool allows copying a credential to another n8n instance"
      },
      "typeVersion": 2.2
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e89a409f-c046-4d54-b580-7e2c0a537d1b",
  "connections": {
    "Settings": {
      "main": [
        [
          {
            "node": "Get Instance Names",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Binary to JSON": {
      "main": [
        [
          {
            "node": "Get Credential Names",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Choose Instance": {
      "main": [
        [
          {
            "node": "Export Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Choose Credential": {
      "main": [
        [
          {
            "node": "Prepare Request Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Credential": {
      "main": [
        [
          {
            "node": "Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Export Credentials": {
      "main": [
        [
          {
            "node": "Get Credentials Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Instance Names": {
      "main": [
        [
          {
            "node": "Choose Instance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Credential Names": {
      "main": [
        [
          {
            "node": "Choose Credential",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Credentials Data": {
      "main": [
        [
          {
            "node": "Binary to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Request Data": {
      "main": [
        [
          {
            "node": "Create Credential",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Form
  • Httprequest
  • Code
  • Set
  • Executecommand

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作